import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)


// 需要左方向动画的路由用this.$router.to('****')
Router.prototype.togo = function(path, par) {
	this.isleft = true
	this.isright = false
	this.push({
		path: path,
		query: par
	})
}
// 需要右方向动画的路由用this.$router.goRight('****')
Router.prototype.goRight = function(path, par) {
	this.isright = true
	this.isleft = false
	this.push({
		path: path,
		query: par
	})
}
// 跳转指定url路径，但是history栈中不会有记录，点击返回会跳转到上上个页面 (就是直接替换了当前页面)，传参跟push一样
Router.prototype.toReplace = function(path, par) {
	this.isleft = true
	this.isright = false
	this.replace({
		path: path,
		query: par
	})
}
// 需要返回按钮动画的路由用this.$router.goBack()，返回上一个路由
Router.prototype.goBack = function(n) {
	this.isright = true
	this.isleft = false
	this.go(n || -1)
}


export default new Router({
	routes: [{
			path: '/',
			name: 'index',
			component: (resolve) => require(['pages/index'], resolve),
			redirect: '/home',
			children: [{
					path: '/home',
					name: 'home',
					component: (resolve) => require(['pages/home'], resolve),
					meta: {
						title: '首页',
						type: 'login'
					}
				},
				{
					path: '/record',
					name: 'record',
					component: (resolve) => require(['pages/record'], resolve),
					meta: {
						title: '发布',
						type: 'login'
					}
				},
				{
					path: '/mine',
					name: 'mine',
					component: (resolve) => require(['pages/mine'], resolve),
					meta: {
						title: '我的',
						type: 'login'
					}
				}
			]
		},
		{
			path: '/login',
			name: 'login',
			component: (resolve) => require(['pages/login'], resolve),
			meta: {
				title: '登录'
			}
		},
		{
			path: '/register',
			name: 'register',
			component: (resolve) => require(['pages/register'], resolve),
			meta: {
				title: '注册'
			}
		},
		{
			path: '/mine/my_mimi',
			name: 'my_mimi',
			component: (resolve) => require(['pages/my_mimi'], resolve),
			meta: {
				title: '我的Mimi',
				type: 'login'
			}
		},
		{
			path: '/mine/set_pwd',
			name: 'set_pwd',
			component: (resolve) => require(['pages/set_pwd'], resolve),
			meta: {
				title: '设置密码',
				type: 'login'
			}
		},
		{
			path: '/mimi/mimi_det/:id',
			name: 'mimi_det',
			component: (resolve) => require(['pages/mimi_det'], resolve),
			meta: {
				title: '详情',
				type: 'login'
			}
		},
		{
			path: '/mine/setting',
			name: 'setting',
			component: (resolve) => require(['pages/setting'], resolve),
			meta: {
				title: '个人中心',
				type: 'login'
			}
		},
		{
			path: '/error/404',
			name: '404',
			component: (resolve) => require(['pages/404'], resolve),
			meta: {
				title: '出错咯'
			}
		},
		{
			path: '/demo/:id',
			name: 'demo',
			component: (resolve) => require(['common/demo'], resolve)
		}
	]
})